//
//  ComposeViewController.m
//  SinaWebo
//
//  Created by wwj on 16/1/11.
//  Copyright © 2016年 亦心. All rights reserved.
//

#import "ComposeViewController.h"
#import "ComposeShareView.h"
#import "ComButtomView.h"
#import "ComposeIdeaViewController.h"
#import "NavigationController.h"
#import "ComposeBaseViewController.h"

@interface ComposeViewController ()<ComposeShareViewDelegate>
@property (weak, nonatomic) ComposeShareView *shareView;
@end

@implementation ComposeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = TRUE;
    self.view.backgroundColor = MyColor(240, 240, 240);
    
    //添加图片
    [self addTopImage];
    
    //添加中间控件
    [self addCenterView];
    
    //添加底部控件
    [self addButtomView];
}

#pragma mark 添加图片
-(void)addTopImage{
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"compose_slogan"]];
    CGFloat imgX = (kScreenW - imageView.frame.size.width) * 0.5;
    imageView.frame = CGRectMake(imgX, 110, imageView.frame.size.width, imageView.frame.size.height);
    [self.view addSubview:imageView];
    
}

#pragma mark 添加中间控件
-(void)addCenterView{
    ComposeShareView *shareView = [ComposeShareView composeShareView];
    shareView.titleArray = @[@"文字", @"照片/视频", @"头条文章",
                             @"签到", @"点评", @"更多"];
    shareView.imgArray = @[@"tabbar_compose_idea", @"tabbar_compose_voice", @"tabbar_compose_headlines",
                           @"tabbar_compose_lbs",@"tabbar_compose_review", @"tabbar_compose_more"];
    shareView.frame = CGRectMake(0, 200, kScreenW, 0);
    shareView.delegate = self;
    [self.view addSubview:shareView];
    _shareView = shareView;
}


#pragma mark 添加底部控件
-(void)addButtomView{
    ComButtomView *buttomView = [ComButtomView comButtomView];
    buttomView.frame = CGRectMake(0, kScreenH - 44, kScreenW, 0);
    [self.view addSubview:buttomView];
    
    __weak typeof (self) weakSelf = self;
    __weak typeof (_shareView) weakShareView = _shareView;
    buttomView.onClickCancelBtn = ^{
        [weakShareView hidden:^{
            [weakSelf performSelector:@selector(dismView) withObject:nil afterDelay:0.3];
        }];
        
    };
}

-(void)composeShareView:(ComposeShareView *)shareView clickBtnType:(ShareType)shareType{
    switch (shareType) {
        case ShareType_Idea://文字
            [self toViewControllerWithClassName:@"ComposeIdeaViewController"];
            break;
            
        case ShareType_Voice://照片,视频
            break;
            
        case ShareType_HeaderLins://头条文章
            break;
            
        case ShareType_Lbs://签到
            break;
         
        case ShareType_Review://点评
            break;
        case ShareType_More://更多
            break;
    }
}

-(void)toViewControllerWithClassName:(NSString *)className{
    ComposeBaseViewController *baseVC = [[NSClassFromString(className) alloc] init];
    NavigationController *naVC = [[NavigationController alloc] initWithRootViewController:baseVC];
    [self presentViewController:naVC animated:YES completion:nil];
    baseVC.block = ^{
        [self dismView];
    };
}

-(void)dismView{
    [self dismissViewControllerAnimated:NO completion:nil];
}

@end
